<?php if(!empty($student_all_profiles)) :?>
	<div class="accord">
	  <?php foreach($student_all_profiles as $v): ?>
			
			<?php
				$profile = isset($v['profile']) && $v['profile'] ? $v['profile'] : FALSE;
				$enrollment = isset($v['enrollment']) && $v['enrollment'] ? $v['enrollment'] : FALSE;
				$student_grades = isset($v['grade']) && $v['grade'] ? $v['grade'] : FALSE;
			?>	

			<h4>SY <?php echo $profile->sy_from.' - '.$profile->sy_to; echo $profile->desc!=''?' ( '.$profile->desc.' )':''; ?></h4>

			<div>
				<?if($student_grades):?>
					
				<div class="table-responsive">

					<table class="table table-compressed table-bordered">
						<tr class="info">
							<td colspan="2" style="font-weight:bold;">LEARNING AREAS</td>
								<?foreach($gp as $k=>$v):?>
									<td  style="font-weight:bold;"><?=strtoupper($v->gp_code);?></td>
								<?endforeach;?>
							<?if(strtolower($enrollment->grade_type) === "smiley"):?>
							<?else:?>
								<td style="font-weight:bold;">FINAL</td>
							<?endif;?>
						</tr>
						
						<?if($student_grades):?>

							<?foreach ($student_grades as $key => $value):?>
								<tr id='<?=$value['sub_id'];?>'>

									<td colspan="2"><?=$value['name'];?></td>

									<?if($value['grades']):?>
										
										<? /* Grading Type is SMILEY */ ?>	
										<?if(strtolower($enrollment->grade_type) === "smiley"):?>

											<?foreach($value['grades'] as $grading_p_id => $v):?>
												<?php if($grading_p_id == "final"){ continue; } // Skip Final, no final for kinder ?>
												<td><?=_smiley($v->value);?></td>
											<?endforeach;?>
										
										<? /* Grading Type is NUMERIC */ ?>
										<?elseif(strtolower($enrollment->grade_type) === "numeric"):?>
										
											<?$final_pass = 0; foreach($value['grades'] as $grading_p_id => $v):?>

												<td>

														<?if($grading_p_id == "final"): $final_pass++;?> <? /* Final Average Compute in the model */ ?>
															<div class="btn-group">
																<!-- <button tabindex="-1" class="btn btn-mini"><span class="badge"><?=$v;?></span></button> -->
																<span title="<?=$v?>" class="badge badge-<?=_numeric_badge($v)?>"><?=_convert($v);?></span>
															</div>
														<?else:?>
															
															<!-- <button tabindex="-1" class="btn btn-mini"><span class="badge badge-inverse"><?=$v->value;?></span></button> -->
															<span title="<?=$v->value?>" class="badge badge-<?=_numeric_badge(floatval($v->value))?>"><?=_convert($v->value);?></span>
															
														<?endif;?>

												</td>
											<?endforeach;?>

											<?if($final_pass <=0):?> <? /* EXtra TD */ ?>
												<td></td>
											<?endif;?>

										<?else:?>
											<td><i class="fa fa-warning"></i>&nbsp; No Grading type was set to the grading level.</td>
										<?endif;?>

									<?else:?>

									<?endif;?>

								</tr>
							<?endforeach;?>
						<?else:?>
							<tr>
								<td colspan="<?=count($value['grades'] + 2);?>">
									<div class="alert alert-danger"><i class="fa fa-warning"></i>&nbsp; Unable to create student grades. No subjects available in the curriculum for this student year level.</div>
								</td>
							</tr>
						<?endif;?>
					</table>

				</div>

				<?else:?>
					<div class="alert alert-warning">Unable to get student Grades. Because 1) Student is not assigned to a section, 2) student is not allowed to view grades and remarks.</div>
				<?endif;?>
			</div>

		<?php endforeach; ?>
	</div>
<?php endif; ?>
<hr>
<div><a href="#" data-reveal-id="gradeTable" class="btn">show grading table</a></div>